package com.yoso.shop.infrastructure.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author shizejin
 * @date 2022/2/24
 * @description:
 */
@Configuration
public class FilePathConfig implements WebMvcConfigurer {
    @Autowired
    private InitConfig initConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * 配置资源映射
         * 意思是：如果访问的资源路径是以“/images/”开头的，
         * 就给我映射到本机的“F:/images/”这个文件夹内，去找你要的资源
         * 注意：F:/images/ 后面的 “/”一定要带上
         */
        registry.addResourceHandler("/" + initConfig.getStaticRequestPath() + "/**").addResourceLocations("file:" + initConfig.getStaticFolderPath());
    }
}
